<?php

/**
 * Created by JetBrains PhpStorm.
 * User: GMC
 * Date: 10/3/13
 * Time: 2:20 PM
 * To change this template use File | Settings | File Templates.
 */
class WidgetTreTodayRSS extends CWidget {
    public $model;

    public function init() {
        $link = "http://tretoday.com/rss/new.rss";
//        // $link = "http://www.raovathot.com/";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $link);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-type: text/xml'
        ));
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
        curl_setopt($ch, CURLOPT_TIMEOUT, 400);

        $content = curl_exec($ch);
        $error = curl_error($ch);
        curl_close($ch);
        if (gettype($content) == "string") {
            $x = new SimpleXmlElement($content);

            $arr = array();

            foreach ($x->channel->item as $entry) {
                array_push($arr, array('title' => $entry->title, 'link' => $entry->link));
            }
            $this->model = $arr;
        }

//        $content = TreTodayCommon::curl("http://tretoday.com/rss/new.rss");
//        $x = new SimpleXmlElement($content);
//
//        $arr = array();
//
//        foreach ($x->channel->item as $entry) {
//            array_push($arr, array('title' => $entry->title, 'link' => $entry->link));
//        }
//        $this->model = $arr;
    }

    public function run() {
        return CWidget::render('widgetTreTodayRSS', array('model' => $this->model));
    }
}